#include "log.h"
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
  {
    static QMutex mutex;
    mutex.lock();
      QString text;
      switch (type) {
      case QtDebugMsg:
          text=QString("Debug:");
          break;
      case QtInfoMsg:
          text=QString("InfoMsg:");
          //fprintf(stderr, "Info: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
          break;
      case QtWarningMsg:
          text=QString("Warning:");
          //fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
          break;
      case QtCriticalMsg:

          text=QString("Critical:");
          //fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
          break;
      case QtFatalMsg:
          text=QString("Fatal:");
          //fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
          break;
      }
      QString context_info=QString("File:(%1)Line:(%2)").arg(QString(context.file)).arg(context.line);
       QString current_date_time=QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss:ddd");
       QString current_date=QString("(%1)").arg(current_date_time);
       QString message=QString("%1 %2 %3 %4").arg(text).arg(context_info).arg(msg).arg(current_date);
       QFile file("Log.txt");
       file.open(QIODevice::WriteOnly|QIODevice::Append);
       QTextStream text_stream(&file);
       text_stream<<message<<"\r\n";
       file.flush();
       file.close();
       mutex.unlock();
}
